local Constants = require ("scripts.constants");
local Block = {
	new = function(row, column)
		local self = {}
		self.markForRemove = false
		self.fills = {
			{name = "red  ", color = {255}}, 
			{name = "green", color = {0, 255}}, 
			{name = "blue ", color = {0, 0, 255}}, 
			{name = "yellow", color = {255, 255}} 
		};
		
		self.windowPosition = {}
		
		self.getFill = function()
			return self.fills[math.random(4)];
		end
		
		self.setFill = function(notSupportedFill)
			local fill = self.getFill();
			while notSupportedFill[fill.name] do
				fill = self.getFill();
			end
			local color = fill.color
			self.fillName = fill.name
			self.displayObject:setFillColor(color[1], color[2], color[3]);
		end
		
		self.init = function()
			local width = Constants.BLOCK_WIDTH * Constants.NUMBER_BLOCKS;
			local height = Constants.BLOCK_HEIGHT * Constants.NUMBER_ROWS;
			local offsetX = (display.contentWidth - width) / 2;
			local offsetY = (display.contentHeight - height) / 2;
			local displayObject = display.newRect(offsetX + (column - 1) * Constants.BLOCK_WIDTH, offsetY + (row - 1) * Constants.BLOCK_HEIGHT, Constants.BLOCK_WIDTH, Constants.BLOCK_HEIGHT);
	    	displayObject.strokeWidth = 1;
			displayObject:setStrokeColor(125);
	    	self.displayObject = displayObject;
	    	self.windowPosition = {row = row, column = column};
		end
		
		self.init();
		return self;
	end
}
return Block;